#include<bits/stdc++.h>
using namespace std;
int n;
int book[20];
int res[20];
void dfs(int num)
{
	if(num>n)
	{
		for(int i=1;i<=n;i++)
		{
			cout<<setw(5)<<res[i]<<"";
		}
		cout<<endl;
	}
	for(int i=1;i<=n;i++)
	{
		if(!book[i])
		{
			book[i]=1;
			res[num]=i;
			dfs(num+1);
			book[i]=0;
		}
	}
}
int main()
{
	cin>>n;
	dfs(1);
	return 0;
 } 
 
